package com.example.fangyh09.fragment;

import android.app.FragmentManager;
import android.app.FragmentTransaction;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.widget.RadioGroup;

public class MainActivity extends AppCompatActivity implements RadioGroup.OnCheckedChangeListener{
    RadioGroup radioGroup;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        radioGroup = (RadioGroup)findViewById(R.id.group);
        radioGroup.setOnCheckedChangeListener(this);

    }

    @Override
    public void onCheckedChanged(RadioGroup group, int checkedId) {
        switch (checkedId) {
            case R.id.first:
                Intent intent = new Intent(this,Activity2.class);
                startActivity(intent);
                break;
            case R.id.second:
                MyFragment2 fragment2 = new MyFragment2();
                FragmentManager manager = fragment2.getFragmentManager();
                FragmentTransaction beginTransaction = manager.beginTransaction();
                beginTransaction.add(R.id.myframe,fragment2);
                beginTransaction.commit();
                break;
            case R.id.third:
                break;
            case R.id.fouth:
                intent = new Intent(this,Activity4.class);
                startActivity(intent);
                break;
        }
    }
}





















